package com.hexinfo.dmpro.data.disaster.recovery.backups.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.http.ResponseEntity;
import com.hexinfo.dmpro.data.disaster.recovery.backups.model.DisasterRecoveryConf;
import com.hexinfo.dmpro.data.disaster.recovery.backups.service.DisasterRecoveryConfService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 生产数据灾备配置表
 *
 * @author wz.li
 * @date 2023-10-09 18:48:56
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/disasterrecoveryconf" )
@Api(value = "disasterrecoveryconf", tags = "生产数据灾备配置表管理")
public class DisasterRecoveryConfController {

    private final  DisasterRecoveryConfService disasterRecoveryConfService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param disasterRecoveryConf 生产数据灾备配置表
     * WrapperEnhancer.like(disasterRecoveryConf); //自动拼接存在值sql的方法
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public ResponseEntity<Object> getDisasterRecoveryConfPage(Page page, DisasterRecoveryConf disasterRecoveryConf) {
        return ResponseEntity.ok(disasterRecoveryConfService.queryList(page,disasterRecoveryConf));
    }


    /**
     * 通过id查询生产数据灾备配置表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public ResponseEntity<Object> getById(@PathVariable("id" ) String id) {
        return ResponseEntity.ok(disasterRecoveryConfService.getById(id));
    }

    /**
     * 新增生产数据灾备配置表
     * @param disasterRecoveryConf 生产数据灾备配置表
     * @return R
     */
    @ApiOperation(value = "新增生产数据灾备配置表", notes = "新增生产数据灾备配置表")
    @PostMapping
    public ResponseEntity<Object> save(@RequestBody DisasterRecoveryConf disasterRecoveryConf) {
        return ResponseEntity.ok(disasterRecoveryConfService.save(disasterRecoveryConf));
    }

    /**
     * 修改生产数据灾备配置表
     * @param disasterRecoveryConf 生产数据灾备配置表
     * @return R
     */
    @ApiOperation(value = "修改生产数据灾备配置表", notes = "修改生产数据灾备配置表")
    @PutMapping
    public ResponseEntity<Object> updateById(@RequestBody DisasterRecoveryConf disasterRecoveryConf) {
        return ResponseEntity.ok(disasterRecoveryConfService.updateById(disasterRecoveryConf));
    }

    /**
     * 通过id删除生产数据灾备配置表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除生产数据灾备配置表", notes = "通过id删除生产数据灾备配置表")
    @DeleteMapping("/{id}" )
    public ResponseEntity<Object> removeById(@PathVariable String id) {
        return ResponseEntity.ok(disasterRecoveryConfService.removeById(id));
    }

    @ApiOperation(value = "手动执行冷备流程", notes = "手动执行冷备流程")
    @GetMapping("/run/{id}" )
    public ResponseEntity<Object> runById(@PathVariable("id" ) String id) {
        disasterRecoveryConfService.runById(id);
        return ResponseEntity.ok("OK");
    }

}
